
var uploader;

/*开机启动项*/
$(function() {

    /*加载 ajax uploader*/
    initUploader();

    /*初始化button点击之后出现的内容，此内容不再updatepanel中*/
    $("#uploadimage").dialog({
        autoOpen: false,
        show: "blind",
        hide: "explode"
    });
    
    /*加载jquery ui dialog对话框的click事件*/
    initUploaderClick();

    
    /*判断图片如果src是空的话就不显示图片*/
    if ($("#ctl00_mainContent_imgPicUrl").attr("src") == "") {
        $("#ctl00_mainContent_imgPicUrl").css("display", "none");
    }
    
    /*加载删除条码之前的确认信息*/
    beforeDelete();
});


/*初始化ajax uploader*/
function initUploader() {
    uploader = new qq.FileUploaderBasic({
        // pass the dom node (ex. $(selector)[0] for jQuery users)
        //element: document.getElementById('file-uploader'),
        button: document.getElementById('btnajaxupload'),
        // path to server-side upload script
        action: 'admin_uploadimage.aspx?action=upload',
        allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
        sizeLimit: 1024000,
        multiple: false,
        debug: true,
        onSubmit: function(id, fileName) {
            if (id > 0) {
                alert("请先删除之前的旧图片!");
                return false;
            }
        },
        onComplete: function(id, fileName, responseJSON) {
            $("#ctl00_mainContent_imgPicUrl").attr("src", responseJSON.filename);
            $("#ctl00_mainContent_imgPicUrl").css("display", "");
            $("#ctl00_mainContent_hfPicUrl").val(responseJSON.filename);
        }
    });
     try 
      {  
         if(typeof(eval("setParams"))=="function")  
         {
             setParams();
         }
       }catch(e)
       {
       //alert("not function"); 
     }
}


/*删除旧的图片，然后重新加载button*/
function deletePreImage() {
    $("#ctl00_mainContent_imgPicUrl").attr("src", "");
    $("#ctl00_mainContent_imgPicUrl").css("display", "none");
    $("#ctl00_mainContent_hfPicUrl").val("");
    initUploader();
}

function newsAddResult(flag){
	if(flag){
		$("#noticesuccess").css("display","normal");
		$("#noticefail").css("display","none");
		setInterval(function(){window.location.href="admin_newslist.aspx"},5000);
	}else{
		$("#noticesuccess").css("display","none");
		$("#noticefail").css("display","normal");
	}
}
function pageJump(url,time){
	setInterval(function(){window.location.href=url},time);
}

/*加载notice信息右边的关闭小标志的点击事件*/
function initCloseNotice() {
    $(".close").click(
            function() {
                $(this).parent().fadeTo(400, 0, function() { // Links with the class "close" will close parent
                    $(this).slideUp(400);
                });
                return false;
            }
  );
}

/*加载上传图片按钮click事件 jquery ui button*/
function initUploaderClick() {    
    $("#openerupload").click(function() {
        $("#uploadimage").dialog("open");
        return false;
    });
}

/*ajax修改信息之后页面必要的更新操作，适合所有页面*/
function AjaxChange() {
    initCloseNotice();
    initUploaderClick();
    timeoutClose();
}
function newsCategoryAdd(url,time){
	initCloseNotice();
	pageJump(url, time);
}
function timeoutClose() {
    setTimeout(function() { $(".close").click(); }, 5000);
}
function initImgFromHidden(){
	$("#ctl00_mainContent_imgPicUrl").attr("src", $("#ctl00_mainContent_hfPicUrl").val());
}

function initSideNav(parent, child) {
    $("#" + parent).addClass("current");
    $("#"+parent).parent().find("a[href='"+child+"']").addClass("current");
    
    $("#main-nav li ul").hide(); // Hide all sub menus
    $("#main-nav li a.current").parent().find("ul").slideToggle("slow"); // Slide down the current menu item's sub menu
}

function beforeDelete(){
	$(".deletebutton").click(function(){
		yes = confirm("是否删除指定的条目？");
		if(!yes){return false;}
	});
}

